const path = require("path");
const HtmlWebpackPugin = require("html-webpack-plugin");
// user-agent  把浏览器的UserAgent变成一个对象
module.exports = {
  entry: "./scr/index.js",
  context: process.cwd(),
  mode: "development",
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "monitor.js",
  },
  devServer: {
    //静态文件根目录
    contentBase: path.resolve(__dirname, "dist"),
    //before 是用来配置路由的 
    before(router){
      router.get('/success',function(req,res){
         res.json({id:1})
      })
      router.post('/error',function(req,res){
        res.sendStatus(500) //500
     })
    }
  },
  plugins: [
    new HtmlWebpackPugin({
      template: "./scr/index.html",
      inject: "head",
    }),
  ],
};
